#!/usr/bin/env python
# $Id: fileeditor.py 70 2009-11-20 15:45:15Z michon1992 $
#
# This file is part of Phennui.
#
# Phennui is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Phennui is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Phennui.  If not, see <http://www.gnu.org/licenses/>.

import imp, os

class FileEditor:

    def __init__(self, filename):
        self.__dict__['config'] = imp.load_source('config_' + os.path.basename(filename), filename)
            
    def __str__(self):
        ret = ''
        for (name, value) in vars(self.__dict__['config']).iteritems():
            if name[0] != '_':
                ret += '%s = %s\n' % (name, repr(value))
        return ret       
    __unicode__ = __str__
    __repr__ = __str__
             
    def __setattr__(self, name, value):
        setattr(self.__dict__['config'], name, value)
        
    def __getattr__(self, name, value = None):
        return getattr(self.__dict__['config'], name, value)

    def __delattr__(self, name):
        delattr(self.__dict__['config'], name)

